<?php
	require_once dirname(BASEPATH) . '/application/models/local/data/_init_model.php';
	
	class mod_cafe_product_category extends _init_model
	{
		public $CAF_PDT_CAT_ID;
		public $CAF_PDT_CAT_NAME;
		public $CAF_PDT_CAT_ORDER;
		
		function __construct(){
			parent::__construct();
		
			$this->tableName = "CAFE_PRODUCT_CATEGORY";
		}
		
		function get_category_list($show_all=false){	
			$this->db->order_by('CAF_PDT_CAT_ORDER', 'ASC');	
			$query = $this->db->get($this->tableName);			
			
			if ($show_all){
				$result = $query->result_array();
				
				$return = array();
				$return[0] = array('CAF_PDT_CAT_ID' => -1,
									'CAF_PDT_CAT_NAME' => 'ทั้งหมด',
									'CAF_PDT_CAT_ORDER' => -1);
				for ($i=0; $i<count($result); $i++)
					array_push($return, array('CAF_PDT_CAT_ID' => $result[$i]['CAF_PDT_CAT_ID'],
												'CAF_PDT_CAT_NAME' => $result[$i]['CAF_PDT_CAT_NAME'],
												'CAF_PDT_CAT_ORDER' => $result[$i]['CAF_PDT_CAT_ORDER']));
				return $return;
			} else			
				return $query->result_array();
		}
		function get_category_list_for_dropdownlist()
		{
			$result = $this->get_category_list();
			
			$return = array();
			if (count($result) > 0)
			{
				foreach ($result as $row)
					$return[$row['CAF_PDT_CAT_ID']] = $row['CAF_PDT_CAT_NAME']; 	
			}
			
			return $return;
		}
	}
?>